var getCookie = readCookie("user")
if(!getCookie){
	location.href="login.htm"
}
var tel=""
$("#myId").val(getCookie)
$(function(){
	getUserInfo()
})


function getUserInfo(){
	$.ajax({
		url:"http://localhost:8080/user/login",
		type:"post",
		dataType:"json",
		data:{
			"id":getCookie
			},
		async:false,
		success:function(data){
			
			$(".img2").prop("src","http://localhost:8080/"+data.data.img)
			tel=data.data.tel
			
			
		}
	})
}

function setUpdatePwd(){
	var pwd1=$("#myPwd").val()
	var pwd2=$("#okPwd").val()
	var pwd=$("#pwd").val()
	if(pwd1!=pwd2){
		$.DialogByZ.Alert({Title: "提示", Content: "两次密码不一致",BtnL:"确定"})
		
	}else if(checkPwd(tel,pwd)==false){
		
		$.DialogByZ.Alert({Title: "提示", Content: "原始密码错误",BtnL:"确定"})
		
	}else{
		updatePwd(pwd2)
	}
	
	
}
function checkPwd(tel1,pwd){
	var valid=false
	$.ajax({
		url:"http://localhost:8080/user/select",
		type:"post",
		dataType:"json",
		data:{
			"tel":tel1,
			"pwd":pwd
			},
		async:false,
		success:function(data){
			if(data.status==1){
				valid=true
			}else{
				valid=false
			}
		}
	})
	return valid
}

function updatePwd(pwd){
	$.ajax({
		url:"http://localhost:8080/user/updatePwd",
		type:"post",
		dataType:"json",
		data:{
			"id":getCookie,
			"pwd":pwd
			},
		async:false,
		success:function(data){
			if(data.status==1){
				$.DialogByZ.Autofade({Content:data.msg})
				
			}else{
				$.DialogByZ.Autofade({Content:data.msg})
				
			}
		}
	})
}


